package chpt11;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UDPServer {
    public static void main(String[] args){
    	//服务器端口号
        int port = 9000;
        //创建服务器端数据报Socket
        try(DatagramSocket server = new DatagramSocket(port)){
            while(true){
                byte[] recvbuf = new byte[1024];
                DatagramPacket dp = new DatagramPacket(recvbuf,recvbuf.length);
                //接收数据报
                server.receive(dp);
                //发送数据报（回显）
                server.send(dp);
            }
        }catch(IOException e){
            e.printStackTrace();
        }
    }
}
